#!/usr/bin/env bash
set -e # 这告诉bash一但有任何一个语句返回非真的值，则退出bash。

PROG_NAME=`basename $0`

function print_help {
    echo -e "Usage: $PROG_NAME [options]"
    echo -e ""
    echo -e "Options:"
    echo -e "  -h, --help"
    echo -e "    Displays help message."
    echo -e ""
    echo -e "  -k KEYWORD, --key=KEYWORD"
    echo -e "    Display keyword."
    echo -e ""
}

KEY_WORD="05 20"

CMD_GETOPT=`getopt -o k:h --long key:,help -n 'example.bash' -- "$@"`
eval set -- "$CMD_GETOPT"
while true ; do
    case "$1" in
        -h|--help) print_help; exit 1 ;;
        -k|--key) KEY_WORD="$2" ; shift 2 ;;
        --) shift; break ;;
        *) echo "Unknown option: $1"; print_help; exit 1 ;;
    esac
done

cat /dev/urandom | hexdump -C | grep --color=auto "$KEY_WORD"
